<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="sec"
	uri="http://www.springframework.org/security/tags"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ page import="kr.co.insoft.framework.config.Authorities"%>
<c:set var="CONTEXT">${pageContext.request.contextPath}</c:set>
<c:set var="cssUrl">${pageContext.request.contextPath}/resources/css</c:set>
<c:set var="jsUrl">${pageContext.request.contextPath}/resources/js</c:set>
<div class="col-sm-12 page-header custom-page-header">
	<h1><spring:message code="menu.configration.cloudvender"/></h1>	
</div>
<form:form modelAttribute="pagingModel" role="form" cssClass="col-sm-12">
	<input id="currentPage" name="currentPage" type="hidden" value="${pagingModel.currentPage}" />
	<div class="form-group">
		<h3><spring:message code="configration.cloud.available.list"/></h3>
		<table class="table table-hover">
			<thead>
				<tr>
					<th><spring:message code="configration.cloud.venderName"/></th>
					<th><spring:message code="configration.cloud.venderType"/></th>
					<th><spring:message code="configration.cloud.venderDesc"/></th>
				</tr>
			</thead>
			<tbody>
				<c:choose>
					<c:when test="${empty venderTypeModel }">
						<tr class="warning">
							<td colspan="3"><spring:message code="list.no.result"/></td>
						</tr>
					</c:when>
					<c:otherwise>
						<c:forEach items="${venderTypeModel }" var="item">
							<tr>
								<td>${item.type }</td>
								<td>${item.typeName }</td>
								<td>${item.updatedDate }</td>
							</tr>
						</c:forEach>
					</c:otherwise>
				</c:choose>
			</tbody>
		</table>
	</div>
	<div class="text-right">
		<c:if test="${fn:contains(buttons , Authorities.CREATE)}">
			<button type="button" class="btn btn-primary syncBtn" ><spring:message code="button.sync"/></button>
		</c:if>
	</div>
	<div class="row"></div>
	<div class="form-group">
		<h3><spring:message code="configration.cloud.using.list"/></h3>
		<table class="table table-hover">
			<thead>
				<tr>
					<th><spring:message code="configration.cloud.venderName"/></th>
					<th><spring:message code="configration.cloud.venderType"/></th>
					<th><spring:message code="configration.cloud.remarks"/></th>
				</tr>
			</thead>
			<tbody>
				<c:choose>
					<c:when test="${empty pagingModel.lists }">
						<tr class="warning">
							<td colspan="3"><spring:message code="list.no.result"/></td>
						</tr>
					</c:when>
					<c:otherwise>
						<c:forEach items="${pagingModel.lists }" var="item">
							<tr >
								<td><a href="#" class="btn_link"  data-link="./view?venderid=${item.venderid }">${item.venderName }</a></td>
								<td>${item.typeName }</td>
								<td>
									<button type="button" class="btn btn-primary btn_link btn-sm" data-link="../connection/lists?venderid=${item.venderid }"><spring:message code="button.param.connection" arguments="${item.connectionCnt }"/></button>
									<button type="button" class="btn btn-primary btn_link btn-sm" data-link="../connection/createForm"><spring:message code="button.param.add" arguments="Connection"/></button>
								</td>
							</tr>
						</c:forEach>
					</c:otherwise>
				</c:choose>
			</tbody>
		</table>
	</div>

	<div class="form-group text-center">
		<c:if test="${not empty pagingModel.lists }">
			<ul class="pagination">
				<li><a href="#" class="pages" data-page="${pagingModel.paging.previousBlock }">&laquo;</a></li>
				<c:forEach items="${pagingModel.paging.pages }" var="pages">
					<c:choose>
						<c:when test="${pages eq pagingModel.paging.currentPageNum }">
							<li class="active"><a href="#" class="pages" data-page="${pages }">${pages }</a></li>
						</c:when>
						<c:otherwise>
							<li><a href="#" class="pages" data-page="${pages }">${pages }</a></li>
						</c:otherwise>
					</c:choose>
				</c:forEach>
				<li><a href="#" class="pages" data-page="${pagingModel.paging.nextBlock}">&raquo;</a></li>
			</ul>
		</c:if>
	</div>
	<div class="text-right">
		<c:if test="${fn:contains(buttons , Authorities.CREATE)}">
			<button type="button" class="btn btn-primary btn_link"
				data-link="./createForm"><spring:message code="button.create"/></button>
		</c:if>
	</div>
</form:form>



<script type="text/javascript">
<!--
$(document).ready(function() {
	$("#viewRow").change(function() {
		$("#currentPage").val("1");
		$("#pagingModel").submit();
	});
});

$(document).on("click", ".syncBtn", function(){
	bootbox.confirm("Vender를 동기화 하시겠습니까?", function(result) {
		if ( result ) {
			Loading.show();
			$.get("./syncVender", null, function(res) {
				
			}).fail(function() {
				bootbox.alert("<spring:message code='common.server.fail'/>"); /* 서버 통신 오류 */
			}).done(function(res) {
				if ( res ) {
					bootbox.alert("동기화 완료하였습니다.", function() {
						location.reload();						
					});
				} else {
					bootbox.alert("동기화 실패");
				}
			}).always(function() {
				Loading.hide();
			});
		}
	});
});
	
		
	
	
//-->
</script>